package com.gitee.wsl.time.schedule.cron

import kotlinx.datetime.DayOfWeek
import kotlinx.datetime.Month

object Cron {

    fun daily(): String {
        return "0 0 * * *"
    }

    fun daily(hour: Int): String {
        return "0 $hour * * *"
    }

    fun daily(hour: Int, minute: Int): String {
        return "$minute $hour * * *"
    }

    fun hourly(): String {
        return "0 * * * *"
    }

    fun hourly(minute: Int): String {
        return "$minute * * * *"
    }

    fun minutely(): String {
        return "* * * * *"
    }

    fun every15seconds(): String {
        return "*/15 * * * * *"
    }

    fun every30seconds(): String {
        return "*/30 * * * * *"
    }

    fun every5minutes(): String {
        return "*/5 * * * *"
    }

    fun every10minutes(): String {
        return "*/10 * * * *"
    }

    fun every15minutes(): String {
        return "*/15 * * * *"
    }

    fun everyHalfHour(): String {
        return "*/30 * * * *"
    }

    fun monthly(): String {
        return "0 0 1 * *"
    }

    fun monthly(day: Int): String {
        return "0 0 $day * *"
    }

    fun monthly(day: Int, hour: Int): String {
        return "0 $hour $day * *"
    }

    fun monthly(day: Int, hour: Int, minute: Int): String {
        return "$minute $hour $day * *"
    }

    fun lastDayOfTheMonth(): String {
        return "0 0 L * *"
    }

    fun lastDayOfTheMonth(hour: Int): String {
        return "0 $hour L * *"
    }

    fun lastDayOfTheMonth(hour: Int, minute: Int): String {
        return "$minute $hour L * *"
    }

    fun weekly(): String {
        return "0 0 * * 1"
    }

    fun weekly(dayOfWeek: DayOfWeek): String {
        return "0 0 * * ${if (dayOfWeek.ordinal == 7) 0 else dayOfWeek.ordinal}"
    }

    fun weekly(dayOfWeek: DayOfWeek, hour: Int): String {
        return "0 $hour * * ${if (dayOfWeek.ordinal == 7) 0 else dayOfWeek.ordinal}"
    }

    fun weekly(dayOfWeek: DayOfWeek, hour: Int, minute: Int): String {
        return "$minute $hour * * ${if (dayOfWeek.ordinal == 7) 0 else dayOfWeek.ordinal}"
    }

    fun yearly(): String {
        return "0 0 1 1 *"
    }

    fun yearly(month: Month): String {
        return yearly(month.ordinal)
    }

    fun yearly(month: Month, day: Int): String {
        return yearly(month.ordinal, day)
    }

    fun yearly(month: Month, day: Int, hour: Int): String {
        return yearly(month.ordinal, day, hour)
    }

    fun yearly(month: Month, day: Int, hour: Int, minute: Int): String {
        return yearly(month.ordinal, day, hour, minute)
    }

    fun yearly(month: Int): String {
        return "0 0 1 $month *"
    }

    fun yearly(month: Int, day: Int): String {
        return "0 0 $day $month *"
    }

    fun yearly(month: Int, day: Int, hour: Int): String {
        return "0 $hour $day $month *"
    }

    fun yearly(month: Int, day: Int, hour: Int, minute: Int): String {
        return "$minute $hour $day $month *"
    }
}
